﻿using System;
using Catchbase.TestTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Catchbase.Service.API.UTest
{
    [TestClass]
    public class RequestBuilderTest : TestBase<RequestBuilder>
    {
        private Uri _uri;
        private Mock<HttpWebRequestGateway> _request;

        protected override void InitializeTest()
        {
            _uri = new Uri("http://localhost");
            _request = new Mock<HttpWebRequestGateway>();
            Mock<HttpRequestGatewayFactory>().Setup(f => f.Create(It.IsAny<Uri>())).Returns(_request.Object);
        }

        [TestMethod]
        public void Build_MustCreateRequestFromFactoryWithUri()
        {
            Subject.Build(HttpMethod.GET, _uri);
            Mock<HttpRequestGatewayFactory>().Verify(f => f.Create(_uri), Times.Once());
        }

        [TestMethod]
        public void Build_MustSetMethod()
        {
            Subject.Build(HttpMethod.GET, _uri);
            _request.VerifySet(r => r.Method = "GET", Times.Once());
        }

        [TestMethod]
        public void Build_MustSetContentType()
        {
            Subject.Build(HttpMethod.GET, _uri);
            _request.VerifySet(r => r.ContentType = "application/json; charset=utf-8");
        }
    }
}